package tat.mock;

import tat.domain.Agregation;
import tat.domain.Association;
import tat.domain.Composition;
import tat.domain.DomainModelRelation;
import tat.domain.DomainModelRelationEndPoint;
import tat.factory.DomainModelRelationFactory;

public class DomainModelRelationFactoryImpl implements DomainModelRelationFactory {

    @Override
    public DomainModelRelation create(final DomainModelRelationEndPoint originEndPoint,
                                      final DomainModelRelationEndPoint destinationEndPoint,
                                      final boolean navigable,
                                      final String relationType) {
    	String relationName = null;

        if (ASSOCIATION.equals(relationType)) {
        	DomainModelRelation relation =  new Association(relationType, originEndPoint, destinationEndPoint, navigable);
        	originEndPoint.addObserver(relation);
            destinationEndPoint.addObserver(relation);
        	return relation;
        }
        if (AGREGATION.equals(relationType)) {
        	DomainModelRelation relation = new Agregation(relationType, originEndPoint, destinationEndPoint, navigable);
        	originEndPoint.addObserver(relation);
            destinationEndPoint.addObserver(relation);
        	return relation;
        }
        if (COMPOSITION.equals(relationType)) {
        	DomainModelRelation relation = new Composition(relationType, originEndPoint, destinationEndPoint, navigable);
        	originEndPoint.addObserver(relation);
            destinationEndPoint.addObserver(relation);
        	return relation;
        }

        throw new IllegalArgumentException("Invalid association type.");
    }

}
